#include "Animator.h"

Animator* Animator::_animator = NULL;

Animator* Animator::Instance()
{
	if (_animator == NULL)
		_animator = new Animator();

	return _animator;
}

void Animator::Animate(Actor* actor, Animation* a, double time)
{
	
 	if (lastTime + (a->getFrameTime() * 1000) < time * 1000)
	{
		lastTime = time * 1000;
		int currFrame = a->getCurrentFrame();

		currFrame++;
		if (currFrame >= a->getTotalFrames())
			currFrame = 0;

		a->setCurrentFrame(currFrame);
		actor->setImage(*a->getCurrentImage());
	}
}

bool Animator::IsPlaying()
{
	return !finish;
}

